package com.club.controller;

import com.club.entity.PageBean;
import com.club.entity.R;
import com.club.service.TClubService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @author zhangfc
 * @date 2022/12/12 16:41
 */
@Api(tags = "社团管理controller")
@RequiredArgsConstructor
@RestController
@RequestMapping("/club")
public class ClubManagerController {

    private final TClubService tClubService;


    /**
     * 提交审核社团信息
     *
     * @param clubMap 参数
     * @return R
     */
    @PostMapping("/submitClub")
    @ApiOperation("提交审核社团信息")
    public R submitClub(@RequestBody Map<String, Object> clubMap) {
        return tClubService.submitClub(clubMap);
    }

    /**
     * 上传社团封面
     *
     * @param file 文件名
     * @return R
     */
    @RequestMapping("/uploadClubImage")
    @ApiOperation("上传社团封面")
    public R uploadClubImage(MultipartFile file) {
        return tClubService.uploadClubImage(file);
    }

    /**
     * 获取社团的列表
     *
     * @param pageBean 分页信息
     * @return R
     */
    @PostMapping("/listClub")
    @ApiOperation("获取社团的列表")
    public R listClub(@RequestBody PageBean pageBean) {
        return tClubService.listClub(pageBean);
    }

    /**
     * 获取当前用户的社团信息
     *
     * @return R
     */
    @PostMapping("/listClubByUser")
    @ApiOperation("获取当前用户的社团信息")
    public R listClubByUser(@RequestBody PageBean pageBean) {
        return tClubService.listClubByUser(pageBean);
    }


    /**
     * 社团审核
     *
     * @param id   主键
     * @param type 类型
     * @return R
     */
    @GetMapping("/auditClub")
    @ApiOperation("社团审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键id", required = true, paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "type", value = "审核类型1-审核通过 2-审核不通过", required = true, paramType = "query", dataType = "Integer")
    })
    public R auditClub(@RequestParam("id") int id,
                       @RequestParam("type") int type) {
        return tClubService.auditClub(id, type);
    }

    /**
     * 根据id集合删除社团
     *
     * @param ids id集合
     * @return R
     */
    @PostMapping("/deleteByIds")
    @ApiOperation("根据id删除社团")
    @ApiImplicitParam(name = "ids", value = "要删除的id集合", required = true, paramType = "body", dataType = "List")
    public R deleteByIds(@RequestBody List<Integer> ids) {
        return tClubService.deleteByIds(ids);
    }


    /**
     * 根据用户id查询已参加的社团
     *
     * @return R
     */
    @GetMapping("/listClubByUserId")
    @ApiOperation("根据用户id查询已参加的社团")
    @ApiImplicitParam(name = "userId", value = "用户主键id", required = true, paramType = "query", dataType = "Integer")
    public R listClubByUserId(@RequestParam("userId") int userId) {
        return tClubService.listClubByUserId(userId);
    }


    /**
     * 根据社团id查询社团详情
     *
     * @param clubId 社团id
     * @return R
     */
    @GetMapping("/msgByClubId/{clubId}")
    @ApiOperation("根据社团id查询社团详情")
    public R msgByClubId(@PathVariable("clubId") int clubId) {
        return tClubService.msgByClubId(clubId);
    }
}
